﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CE.iPhone.PList;
using System.IO;
using System.Xml;
using CE.iPhone.PList.Internal;
using System.Text;

namespace qq6789com
{
    /// <summary>
    /// GetIphoneInfo 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class GetIphoneInfo : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetIphonePlistInfo(string attr,string ipaAddress)
        {
            string values = string.Empty;
            string infoPlistAddress = UnzipHelper.unzipFileIOS2(ipaAddress);
                PListRoot root = PListRoot.Load(infoPlistAddress);
                using (MemoryStream memStream = new MemoryStream())
                {
                    root.Save(memStream, PListFormat.Xml);
                    byte[] bys = memStream.ToArray();                 
                    PListDict dic = (PListDict)root.Root;
                    PListString name = (PListString)dic[attr];
                    UTF8Encoding utf8 = new UTF8Encoding();
                    Byte[] encodedBytes = utf8.GetBytes(name.Value);
                    string decodedString = utf8.GetString(encodedBytes);
                    values = decodedString;
            }                           
            return values;

        }

        public   void stream2file(byte[] bytes, string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(bytes);
            bw.Close();
            fs.Close();
        }


    
    }
}
